package com.ssy.lingxi.logistics.controller;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.model.vo.PageVO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.logistics.api.dto.request.CommonIdRequest;
import com.ssy.lingxi.logistics.model.request.CommonStatusRequest;
import com.ssy.lingxi.logistics.model.request.CompanyRequest;
import com.ssy.lingxi.logistics.model.response.CompanyListResponse;
import com.ssy.lingxi.logistics.model.response.CompanyResponse;
import com.ssy.lingxi.logistics.service.ICompanyService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @menu 物流能力 - 物流管理 - 物流公司管理
 * @author yzc
 * @version 2.0.0
 * @date 2020/7/10
 */
@RestController
@RequestMapping("/logistics/company")
public class CompanyController extends BaseController {

    @Resource
    private ICompanyService companyService;

    /**
     * 物流公司分页列表
     * @param request 接口参数
     * @return 返回结果
     */
    @GetMapping("/page")
    public Wrapper<PageData<CompanyListResponse>> pageCompany(PageVO request) {
        UserLoginCacheDTO sysUser = getSysUser();
        return companyService.pageCompany(request, sysUser);
    }

    /**
     * 物流公司查询
     * @param id 主键id
     * @return 返回结果
     */
    @GetMapping(value = "/get")
    public Wrapper<CompanyResponse> getCompany(@RequestParam(name = "id") Long id) {
        UserLoginCacheDTO sysUser = getSysUser();
        return companyService.getCompany(id);
    }

    /**
     * 物流公司添加
     * @param request 接口参数
     * @return 返回结果
     */
    @PostMapping(value = "/add")
    public Wrapper<Void> addCompany(@RequestBody @Validated(CompanyRequest.Add.class) CompanyRequest request) {
        UserLoginCacheDTO sysUser = getSysUser();
        return companyService.addCompany(request, sysUser);
    }

    /**
     * 物流公司修改
     * @param request 接口参数
     * @return 返回结果
     */
    @PostMapping(value = "/update")
    public Wrapper<Void> updateCompany(@RequestBody @Validated(CompanyRequest.Update.class) CompanyRequest request) {
        UserLoginCacheDTO sysUser = getSysUser();
        return companyService.updateCompany(request, sysUser);
    }

    /**
     * 物流公司停用/启用
     * @param request 接口参数
     * @return 返回结果
     */
    @PostMapping(value = "/enable")
    public Wrapper<Void> updateStatusCompany(@RequestBody @Validated CommonStatusRequest request) {
        UserLoginCacheDTO sysUser = getSysUser();
        return companyService.updateStatusCompany(request, sysUser);
    }

    /**
     * 物流公司删除
     * @param request 接口参数
     * @return 返回结果
     */
    @PostMapping(value = "/delete")
    public Wrapper<Void> deleteCompany(@RequestBody @Validated CommonIdRequest request) {
        UserLoginCacheDTO sysUser = getSysUser();
        return companyService.deleteCompany(request, sysUser);
    }
}
